/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.modudf;

import java.awt.Component;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class MoveMouseListener implements MouseListener, MouseMotionListener {
    Component target;
    Point pMouse;
    Point pFrame;
    
    public MoveMouseListener(Component target) {
        this.target = target;
    }

    public void mouseClicked(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mousePressed(MouseEvent e) {
        this.pMouse = e.getLocationOnScreen();
        this.pFrame = this.target.getLocation();
    }

    public void mouseReleased(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseExited(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseDragged(MouseEvent e) {
        Point current = e.getLocationOnScreen();
        Point offset = new Point (
                (int) current.getX() - (int) pMouse.getX(),
                (int) current.getY() - (int) pMouse.getY()
                );
        target.setLocation(new Point(
                (int) (pFrame.getX() + offset.getX()),
                (int) (pFrame.getY() + offset.getY())
                ));
    }

    public void mouseMoved(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

}

